package com.zack.paymoudle;

import com.zack.paymoudle.alipay.Alipay;
import com.zack.paymoudle.alipay.AlipayConfig;
import com.zack.paymoudle.wxpay.WeiXinPay;
import com.zack.paymoudle.wxpay.WeiXinPayConfig;

/**
 * Created by Zackv on 2018/4/25.
 */

public class PayFade {
    private static WeiXinPay weiXinPay;
    private static Alipay aliPay;


    public PayFade(PayResultListener listener){
        if(aliPay == null) {
            aliPay = new Alipay(listener);
        }
        if(weiXinPay == null) {
            weiXinPay = new WeiXinPay(listener);
        }
    }



    public void pay(AlipayConfig aliPayConfig) {
        aliPay.setConfig(aliPayConfig);
        pay(aliPay);
    }

    public void pay(WeiXinPayConfig weiXinPayConfig){
        weiXinPay.setConfig(weiXinPayConfig);
        pay(weiXinPay);
    }

    private void pay(final PayFunction payModule){
        payModule.checkPayState(new CheckStateListener(){
            @Override
            public void checkState(boolean state) {
                if(state){
                    payModule.payOrder();
                }
            }
        });
    }
}
